﻿@{
    ViewBag.Title = "Company";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
}
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search(0)" plain="true">刷新</a>
                    <a class="mini-button" id="edit" name="edit" iconCls="icon-edit" onclick="modify" plain="true" visible="@ViewBag.edit">修改</a>
                    <a class="mini-button" id="save" name="copy" iconCls="icon-expand" onclick="copyGoodsInfo" plain="true" visible="@ViewBag.save">下发商品资料</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>       
    </div>
    <table>
        <tr>
            <td width ="70px" align="right">注册日期：</td>
            <td width ="310px">
                @Html.Partial("~/Views/Modular/dxDateRangeXp.cshtml") 
            </td>
            <td width ="120px" >
                <input id="FDateType" name="FDateType" class="mini-combobox" style="width:120px;" TabIndex="1" value ="0" data ="dDateData"/> 
            </td>
            <td width ="90px" align="right">编码或名称: </td>
            <td width ="120px" ><input class="mini-textbox" width ="120px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()"/></td>
        </tr>
    </table>
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
            borderStyle="border:1;" url="GetListson" 
            allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
            onrowdblclick="modify"  sortMode="client" multiSelect="true">
            <div property="columns">
                <div type="checkcolumn" ></div>
                <div type="indexcolumn" width="40" headerAlign="center" >序号</div>  
                <div field="FUserNumber" name="FUserNumber" width="90" headeralign="center" allowsort="true">用户编码</div>                          
                <div field="FNumber" name="FNumber" width="90" headeralign="center" allowsort="true">商户编码</div>
                <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">商户名称</div>                            
                <div field="FParentNumber" name="FParentNumber" width="80" headeralign="center" allowsort="true">上级编码</div>
                <div field="FParentName" name="FParentName" width="150" headeralign="center" allowsort="true">上级商户</div>
                <div field="InviteCorp" name="InviteCorp" width="100" headeralign="center" allowsort="true">邀请商户</div>
                <div field="StockName" name="StockName" width="120" headeralign="center" allowsort="true">默认门店</div>
                <div field="FAddress" name="FAddress" width="100" headeralign="center" allowsort="true">地址</div>
                <div field="FManager" name="FManager" width="80" headeralign="center" allowsort="true">联系人</div>
                <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">电话</div>
                <div field="FCreatDate" name="FCreatDate" dateFormat="yyyy-MM-dd hh:mm:ss" width="130" headeralign="center" allowsort="true">注册时间</div>
                <div field="FEndTime" dateFormat="yyyy-MM-dd hh:mm:ss" name="FEndTime" width="130" headeralign="center" allowsort="true">到期时间</div>
            </div>
        </div>
    </div>

<script>
    var dDateData = [{ "id": "0", "text": "不过滤" }, { "id": "1", "text": "按创建日期过滤" }, { "id": "2", "text": "按到期过滤" }];

    mini.parse();
    var grid = mini.get("datagrid1");
    FormShown();
    function FormShown() {
        var nowDate = new Date();
        mini.getbyName("FDate1").setValue("2016-01-01");
        mini.getbyName("FDate2").setValue(nowDate);
        search();
    }

    function search(type) {
        var cDate1 = mini.getbyName("FDate1").getFormValue();
        var cDate2 = mini.getbyName("FDate2").getFormValue();
        var mDateType = mini.getbyName("FDateType").getValue();
        var json = "[{";
        json = json + "'mNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
        json = json + '"mDate1":' + '"' + cDate1 + '",';
        json = json + '"mDate2":' + '"' + cDate2 + '",';
        json = json + '"mDateType":' + '"' + mDateType + '",';
        json = json + "'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]";
        grid.load({ mjson: json });
    }
    function setkeyPress() {
        search();
    }
    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/CompanyInfo",
                title: "商户资料", width: 670, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager, FTelephone: row.FTelephone,
                        FAddress: row.FAddress, FEMail: row.FEMail, FBillPrtName: row.FBillPrtName, FParentID: row.FParentID, FAdvUrl: row.FAdvUrl,
                        FCustName: row.FCustName, FRemark: row.FRemark, FShopType: row.FShopType
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function copyGoodsInfo() {
        mini.confirm("确定要下发所有商品到选择的分店吗？", "提示",
            function (action) {
                if (action == "ok") {
                    copyGoodsInfoExe();
                }
            }
       );
    }

    function copyGoodsInfoExe() {
        var rows = grid.getSelecteds();
        var data = '[';
        var datarow = 0;
        for (var i = 0; i < rows.length; i++) {
            if (datarow > 0) data = data + ",";
            data = data + '{"FItemID":' + rows[i].FItemID + ',"FNumber":"' + rows[i].FNumber + '"}';
            datarow = datarow + 1;
        }
        data = data + "]";
        if (rows.length > 0) {
            var json = '{"mCorpList":' + data + ',';
            json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
            $.post('CopyGoodsInfo', { mjson: json }, function (data) {
                var ret = mini.decode(data);
                mini.alert(ret.msg);             
            });
        }
        else {
            mini.alert("请选择商品进行批量设置");
        }
    }

</script>